fix(desktop): derive avatar initials by character, not code unit - #5992
fix(desktop): derive avatar initials by character, not code unit#5992Chessing234 wants to merge 3 commits into
Conversation
`getInitials` took `part[0]`, a UTF-16 code unit. A name whose first letter lives outside the Basic Multilingual Plane is a surrogate pair, so that returned half of one — not a character. CJK Extension B appears in ordinary Chinese and Japanese given names, and every avatar for such a person rendered `�`. Iterate code points, and take two of them before joining rather than slicing two code units off the result, so the second initial cannot be halved either. Signed-off-by: Taksh <takshkothari09@gmail.com>
Combining marks are neither `\p{L}` nor `\p{N}`, so `getInitials` replaced
them with a separator and cut words apart from the inside. "अनिल कुमार" split
at the vowel sign into "अन" and "ल", producing "अल" — two letters from the
middle of the first name, with the surname never reached. A one-word name
like "नमस्ते" produced two initials where there is one word to initial.
Devanagari, Burmese, Thai and Khmer names take marks in ordinary spelling.
Keep `\p{M}` alongside letters and numbers. Punctuation is still stripped, so
"B (relay)" still gives "BR".
Signed-off-by: Taksh <takshkothari09@gmail.com>
themiguelamador
left a comment
There was a problem hiding this comment.
The astral-code-point and word-splitting fixes are good, but the new implementation still truncates initials at a code point rather than a grapheme cluster. For example, decomposed E\u0301lodie Durand returns ED and drops the accent even though the new contract says combining marks remain part of the word. The existing Indic expectations similarly discard the surname vowel sign (कु → क) and the first Burmese grapheme (မေ → မ). Join controls are also stripped, so an ordinary joined cluster such as क्ष is split into two initials. I prepared local signed commit d694a2c6e, using the project’s established Intl.Segmenter approach, preserving Join_Control, and adding/correcting regressions. Verification: 13 focused tests; all 4,963 desktop unit tests; TypeScript; Biome; file-size gate; pre-commit. I attempted to push it to the contributor branch because maintainer edits are enabled, but GitHub returned 403.
Review caught that the previous commits stopped half way. Moving from code
units to code points fixed the lone surrogate, but an initial is neither:
- decomposed `Élodie Durand` gave `ED`, dropping the accent, though the
contract these commits added says a mark stays with its letter
- `अनिल कुमार` gave `अक`, dropping the surname's vowel sign — `कु` is one
cluster
- `မောင် မောင်` gave `မမ` rather than `မေမေ`
- `क्ष` was split into two initials, because the zero-width joiner holding it
together is neither a letter nor a mark and so acted as a word separator
Segment by grapheme via `Intl.Segmenter`, guarded and falling back to a code
point exactly as `MessageLinkPill` does, and keep `\p{Join_Control}` in the
word-separation set alongside `\p{M}`.
Two of the tests added earlier asserted the code-point results (`अक`, `မ`) as
if they were correct. They were not; they are corrected here rather than kept
as a description of the bug.
Signed-off-by: Taksh <takshkothari09@gmail.com>
|
you're right on all four, thanks — i reproduced each one before changing anything: the code-point step fixed the lone surrogate and then stopped. worse, two of the tests i added asserted the code-point results ( pushed
one note on the decomposed case: the initial keeps the input's own normalization, so verification: 14 focused tests, full desktop suite 4964 passed / 0 failed, |
themiguelamador
left a comment
There was a problem hiding this comment.
Re-reviewed current head 3bb067a19. This resolves the prior grapheme-cluster finding: initials now use Intl.Segmenter, preserve join controls, retain decomposed accents and Indic vowel signs, and keep a code-point fallback for older engines. The new expectations and regressions cover the reported cases.
Verified with the full desktop unit suite, TypeScript, focused Biome, file-size ratchet, and git diff --check. No remaining findings.
Found by probing
getInitialswith non-Latin names; no issue filed. It feeds every avatar fallback in the app —UserAvatar,ProfileAvatar,IdentityInitialsAvatar,CommunityRail.Two separate bugs, one commit each.
Half a surrogate pair. The function took
part[0], a UTF-16 code unit. A name whose first letter lives outside the Basic Multilingual Plane is a surrogate pair, so that returned half of one — not a character:CJK Extension B appears in ordinary Chinese and Japanese given names, so every avatar for such a person rendered
�. Now iterating code points, and taking two of them before joining rather than slicing two code units off the result, so the second initial can't be halved either.A word cut in half at a combining mark. Marks are neither
\p{L}nor\p{N}, so they were replaced with a separator — cutting words apart from the inside:अनिल कुमारअलअकनमस्तेनतनမောင်မောင်မငမ"अनिल कुमार" split at the vowel sign into "अन" and "ल", so both initials came from the middle of the first name and the surname was never reached; a one-word name produced two initials where there is one word to initial. Devanagari, Burmese, Thai and Khmer names take marks in ordinary spelling.
\p{M}is now kept alongside letters and numbers — punctuation is still stripped, and the existing"B (relay)" → "BR"case is pinned by a test in both commits.Verified locally at this head:
pnpm test— 4961 passed, 0 failed (4954 before, plus the 7 new)pnpm check— clean; its 2 warnings and 2 infos are pre-existing and identical onmainpnpm build— succeededNote: I'm an outside contributor, so the workflow runs here sit at
action_requireduntil a maintainer approves them; only the DCO check reports on its own.